package com.wangwenjun.concurrency.chapter14.happenbefore;

import java.util.concurrent.TimeUnit;

/**
 * @Package: com.wangwenjun.concurrency.chapter14.happenbefore
 * @ClassName: UseHappenBefore
 * @Author: lujieni
 * @Description: 1
 * @Date: 2021-03-22 10:46
 * @Version: 1.0
 */
public class UseHappenBefore01 {

    public static void main(String[] args) throws Exception {
        Bye bye = new Bye();
        new Thread(()->{
            while (bye.age == 0){
                int count = bye.count;
            }
        }).start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(()->{
            bye.change();
        }).start();



    }

    private static class Bye{
        int age = 0;
        volatile int count = 0;

        private void change(){
            age = 100;
            count = 10;
        }
    }











}